package com.zengqingfa.quartz.demo.config;

import com.zengqingfa.quartz.demo.job.StartOfDayJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *
 * @fileName: QuartzConfig
 * @author: zengqf3
 * @date: 2021-6-2 14:20
 * @description:
 */
@Configuration
public class QuartzConfig {

    @Bean
    public JobDetail jobDetail() {
        JobDetail jobDetail = JobBuilder.newJob(StartOfDayJob.class).withIdentity("start_of_day", "start_of_day")
                .storeDurably().build();
        return jobDetail;
    }

    @Bean
    public Trigger trigger() {
        Trigger trigger = TriggerBuilder.newTrigger().forJob(jobDetail()).withIdentity("start_of_day", "start_of_day")
                .startNow()
                // 每天0点执行
                .withSchedule(CronScheduleBuilder.cronSchedule("0/1 * * * * ?")).build();
        return trigger;
    }
}
